Introduction to the File Allocation Table (FAT)

Every disk or hard disk, that has been formatted with the FAT system is built as follows

The write process
The operating system writes system information like file size and first cluster number to the directory entry, position information to the FAT, and data itself to the data area.

The read process
(1) System information, like file name, size and first cluster number is determined from the directory entry.
(2) Further cluster numbers are found from the file allocation table (FAT) and read from the corresponding clusters in the data area.

 

The file system exists from a number of special areas of the disk set aside for organization when the disk is formatted: the master boot record, the partition table, the boot record, the file allocation table (from which the FAT system takes its name), and the root directory. At a low level, disk are organized into 512 byte groups called sectors. The FAT system allocates space for files using a unit called a cluster, made up of an integral number of sectors.

A boot record is a sector which contains code that can is executed by the computer. The master boot record is the first boot record that the computer executes when it accesses the hard disk. Additonally a boot record contains important information about the FAT file system, e.g. the cluster size and the positions of the file allocation table, data area and the root directory.

The file allocation table (FAT), located behind the boot record is a database that associates clusters of disk space with files. It has one entry (each 12,16 or 32 bits) for each cluster. Because the first two entries are reserved for the file system, the third entry and those following are assigned to clusters of disk space (data area). Files saved in the data area are not necessarily stored successively and therefore the operating system has to know where a complete file is located in the data area. That is the task of the FAT. For any cluster that is used by a file but is not the file's last cluster, the FAT entry contains the number of the next cluster used by the file. When a program asks the operating system (OS) to provide the content of a file, the OS has to read the first cluster of a file. It then looks at the corresponding first cluster entry in the FAT and knows the next cluster number where the file continues. Now it reads the associated cluster in the data area. After this cluster is also totally read the OS repeats this method until the whole file is read. This way of organizing a file is called the FAT chain.

FAT entries may contain a few special values to indicate that

But from where does the OS know what files are on the disk and where to find the first cluster of that files? That is the reason for the directory entries which are also stored in the data area. Each directory entry has a size of 32 byte and includes information about the file or directory name, size, first cluster number and its attributes.